/**
 *  表单工具类;
 * @author    Long Ronghao
 * @copyright (c) 2013,  Amdocs
 * @version   0.1
 * @date      <ul>
 * <li>2013-08-07</li>
 * </ul>
 *
 */
function FormHelper(theForm){
	this.form = theForm;
}

FormHelper.prototype.setInputValue=function(field,value){
	this.form[field].value=value;
};
//赋值单选框
FormHelper.prototype.setRadioValue=function(field,value){
	var arr = this.form[field];
	for(var n=0;n<arr.length;n++){
		arr[n].checked=(arr[n].value == value);
		if(arr[n].checked)break;
	}
};
//赋值多选框
FormHelper.prototype.setCheckValues=function (field,values){
 	var arr = this.form[field];
	for(var n=0;n<arr.length;n++){
		arr[n].checked=false;
		for(var i=0;i<values.length;i++){
			if(arr[n].value == values[i]){
				arr[n].checked=true;
				break;	
			}
		}
	}
};
//赋值下拉框
FormHelper.prototype.setSelectValue=function (field,value){
	var arr = this.form[field].options;
	for(var n=0;n<arr.length;n++){
		arr[n].selected=(arr[n].value == value);
	}
};
//赋值下拉多选框
FormHelper.prototype.setSelectValues=function (field,values){
	var arr = this.form[field].options;
	for(var n=0;n<arr.length;n++){
		arr[n].selected=false;
		for(var i=0;i<values.length;i++){
			if(arr[n].value == values[i]){
				arr[n].selected=true;
				break;	
			}
		}
	}
};
//赋值combo
FormHelper.prototype.setComboValue=function (field,value){
	Ext.getCmp(field+'_ext').setValue(value);
};
//取值单选
FormHelper.prototype.getRadioValue = function(field){
	var arr = this.form[field];
	for(var n=0;n<arr.length;n++){
		if(arr[n].checked){
			return arr[n].value;
		}
	}
	return "";
};
//取值多选
FormHelper.prototype.getCheckValues = function(field){
	var ret = new Array();
	var arr = this.form[field];
	for(var n=0;n<arr.length;n++){
		if(arr[n].checked){
			ret[ret.length]=arr[n].value;
		}
	}
	return ret;
};
//取值下拉框
FormHelper.prototype.getSelectValue = function(field){
	var arr = this.form[field];
	for(var n=0;n<arr.length;n++){
		if(arr[n].selected){
			return arr[n].value;
		}
	}
	return "";
};
//取值下拉多选框
FormHelper.prototype.getSelectValues = function(field){
	var ret = new Array();
	var arr = this.form[field];
	for(var n=0;n<arr.length;n++){
		if(arr[n].selected){
			ret[ret.length]=arr[n].value;
		}
	}
	return ret;
};

/** ext record data
 * @param rec
 * @param fld
 * @returns
 */
function getRecordValue(rec, fld){
	var v = rec.get(fld);
	if( v && (v!='null') && (v!='NULL')  ){
		return v;
	}
	return '';
}

